// 管理用户数据相关

import { defineStore } from 'pinia'
import { ref } from 'vue'
import { adminLoginAPI } from "@/apis/admin";
export const useAdminStore = defineStore('admin', () => {

  // 1. 定义管理用户数据的state
  const adminInfo = ref({})
  // 2. 定义获取接口数据的action函数
  const getAdminInfo = async ({ account, password }) => {
    const res = await adminLoginAPI({ account, password })
    adminInfo.value = res.data
  }

    // 退出时清除用户信息
    const clearAdminInfo = () => {
      adminInfo.value = {}
    }

  // 3. 以对象的格式把state和action return
  return {
    adminInfo,
    getAdminInfo,
    clearAdminInfo
  }
}, {
  persist: true,
})